﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ch04
{
    class Class7
    {
        static void Main(string[] args)
        {
            Console.Write("年份：");
            int year = int.Parse(Console.ReadLine());
            Console.Write("月份：");
            int month = int.Parse(Console.ReadLine());

            //定义变量保存相差总天数
            int sum = 0;

            //计算起始位置
            //1、计算当前年月的1日距离1900-1-1相差多少天

            //对年份循环
            for (int i = 1900; i < year; i++)
            {
                sum += i % 4 == 0 && i % 100 != 0 || i % 400 == 0 ? 366 : 365;
            }
            //对月份循环
            for (int i = 1; i < month; i++)
            {
                switch (i)
                {
                    case 2: sum += i % 4 == 0 && i % 100 != 0 || i % 400 == 0 ? 29 : 28; break;
                    case 4:
                    case 6:
                    case 9:
                    case 11: sum += 30; break;
                    default: sum += 31; break;
                }
            }

            //2、相差多少天数%7，得出当前月第一天是星期几，也就是起始位置
            int start = sum % 7;

            //计算这个月有多少天
            int days = 0;

            switch (month)
            {
                case 2: days = year % 4 == 0 && year % 100 != 0 || year % 400 == 0 ? 29 : 28; break;
                case 4:
                case 6:
                case 9:
                case 11: days = 30; break;
                default: days = 31; break;
            }
            
            Console.WriteLine("一\t二\t三\t四\t五\t六\t日");
            //根据起始位置，输出\t
            for (int i = 0; i < start; i++)
            {
                Console.Write("\t");
            }
            //循环输出每一个天
            for (int i = 1; i <= days; i++)
            {
                Console.Write("{0:00}\t", i);
                if ((start + i) % 7 == 0)
                {
                    Console.WriteLine();
                }
            }

            Console.WriteLine("\n");
        }
    }
}
